import java.util.ArrayList;
import java.util.List;

public class AnimalKeeper extends User{
    private String keeperName;
    private Integer keeperAge;
    private List<Animal> animals = new ArrayList<Animal>();

    public AnimalKeeper(String keeperName) {
        super.setUserName(keeperName);
    }

    public String getKeeperName() {
        return keeperName;
    }

    public void setKeeperName(String keeperName) {
        this.keeperName = keeperName;
    }

    public Integer getKeeperAge() {
        return keeperAge;
    }

    public void setKeeperAge(Integer keeperAge) {
        this.keeperAge = keeperAge;
    }

    public boolean addAnimal(Animal animal) {
        animals.add(animal);
        return true;
    }

    public boolean deleteAnimal(Animal animal) {
        return animals.remove(animal);
    }

    public boolean deleteAnimal(String animalName) {
        Animal animal = findAnimal(animalName);
        if (animal != null) {
            return animals.remove(animal);
        }
        return false;
    }

    public boolean updateAnimal(Animal oldAnimal, Animal newAnimal) {
        if (deleteAnimal(oldAnimal)) {
            return addAnimal(newAnimal);
        }
        return false;
    }

    public Animal findAnimal(String animalName) {
        for (Animal animal : animals) {
            if (animal.getUserName().equals(animalName)) {
                return animal;
            }
        }
        return null;
    }

    public List<Animal> getAnimals() {
        return animals;
    }

    public String displayAllAnimals() {
        StringBuilder displayMessage = new StringBuilder();
        for (Animal animal : animals) {
            displayMessage.append(animal.getUserName()).append("\n");
        }
        return displayMessage.toString();
    }
}
